package collectionTaks;

import org.w3c.dom.ls.LSLoadEvent;

import java.util.ArrayList;
import java.util.List;

/**  练习List集方法：get()、set()、重载remove()、重载add()、subList() */
public class ListDemo02 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        //添加元素
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list"+list);//list[one, two, three, four, five]

        System.out.println(list.get(3));//获取list集合中下标为3的元素   four

        list.set(3,"six");//将集合list中下标为3的元素替换为six
        System.out.println("替换操作后list"+list);//[one, two, three, six, five]

        list.remove(1);//删除下标为1的元素  two
        list.remove("three");//删除集合中three元素
        System.out.println("删除操作后list"+list);//[one, six, five]

        list.add(2, "seven");//向集合list中插入元素下标为2
        System.out.println(list);//[one, six, seven, five]

        System.out.println(list.subList(1,3)); //[six, seven]  含头不含尾









    }
}
